Skip to content

[nodejs] Handle Next.js weblog shutdown telemetry#6814

Draft
smola wants to merge 2 commits intomainfrom
smola/nextjs-sigterm
Draft

[nodejs] Handle Next.js weblog shutdown telemetry#6814
smola wants to merge 2 commits intomainfrom
smola/nextjs-sigterm

Conversation

@smola
Copy link
Copy Markdown
Member

@smola smola commented Apr 27, 2026

Motivation

While fixing SIGTERM dispatch to weblogs (see #6804) I noticed the Next.js weblog does not exit gracefully on SIGTERM. Its signal handler calls process.exit, which does not run any beforeExit hook in dd-trace-js.

Changes

  • Register signal handlers to call exit hooks from dd-trace-js. These signal handlers are the recommended way to implement graceful shutdown in Next.js, see https://nextjs.org/docs/pages/guides/self-hosting#manual-graceful-shutdowns
    • Adds a grace period of 10s to allow flush actions to finish. A fixed timeout is not ideal, but still better than the undocumented 10s docker stop timeout.
  • If a later version of dd-trace-js implements a publich shutdown/flush method, that might be used here instead of the current hack.
  • Change Dockerfile and app.sh to use exec to run nextjs, so that signals to the container on docker stop are properly dispatched to the Node app.

Workflow

  1. ⚠️ Create your PR as draft ⚠️
  2. Work on you PR until the CI passes
  3. Mark it as ready for review
    • Test logic is modified? -> Get a review from RFC owner.
    • Framework is modified, or non obvious usage of it -> get a review from R&P team

🚀 Once your PR is reviewed and the CI green, you can merge it!

🛟 #apm-shared-testing 🛟

Reviewer checklist

  • Anything but tests/ or manifests/ is modified ? I have the approval from R&P team
  • A docker base image is modified?
    • the relevant build-XXX-image label is present
  • A scenario is added, removed or renamed?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 27, 2026

CODEOWNERS have been resolved as:

utils/build/docker/nodejs/nextjs/src/instrumentation.js                 @DataDog/dd-trace-js @DataDog/system-tests-core
utils/build/docker/nodejs/nextjs.Dockerfile                             @DataDog/dd-trace-js @DataDog/system-tests-core
utils/build/docker/nodejs/nextjs/next.config.js                         @DataDog/dd-trace-js @DataDog/system-tests-core

@smola smola marked this pull request as ready for review April 27, 2026 10:32
@smola smola requested review from a team as code owners April 27, 2026 10:32
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 220851921c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread utils/build/docker/nodejs/nextjs/package.json Outdated
@smola smola requested a review from simon-id April 27, 2026 10:49
@smola smola force-pushed the smola/nextjs-sigterm branch from 2208519 to cd72628 Compare April 28, 2026 09:23
@smola smola marked this pull request as draft April 28, 2026 09:24
@smola smola mentioned this pull request Apr 28, 2026
5 tasks
@smola smola force-pushed the smola/nextjs-sigterm branch from cd72628 to dae1137 Compare April 29, 2026 09:33
@datadog-datadog-prod-us1
Copy link
Copy Markdown

datadog-datadog-prod-us1 Bot commented Apr 29, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6bd6d14 | Docs | Datadog PR Page | Give us feedback!

@smola smola force-pushed the smola/nextjs-sigterm branch from dae1137 to 5546e7b Compare April 30, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant